package com.zhifou.controller;

import com.zhifou.model.User;
import com.zhifou.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Desc:
 * @Author: 公众号：知否技术
 * @date: 下午5:08 2022/5/7
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/list")
    @ResponseBody
    public Object getUserList() {
        List<User> userList = userService.getUserList();
        return userList;
    }

    @RequestMapping("/hello")
    public String sayHello(Model model) {
        model.addAttribute("msg", "你好，李银河，我是王小波。");
        return "/hello";
    }


    @GetMapping("/thymeleafPage")
    public String thymeleafPage(Map<String, Object> map) {
        //通过 map 向前台页面传递数据
        map.put("name", "张三");
        return "thymeleaf/thymeleafPage"; // 视图名称，对应templates/thymeleafPage.html
    }

}
